package com.elitetyc.customview;

import android.app.AlertDialog;
import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Intent;
import android.inputmethodservice.Keyboard;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.elitetyc.customview.activity.AnQuanJianPanActivity;
import com.elitetyc.customview.activity.DatePickerActivity;
import com.elitetyc.customview.activity.DialogActivity;
import com.elitetyc.customview.activity.HlqhActivity;
import com.elitetyc.customview.activity.ImageMoveActivity;
import com.elitetyc.customview.activity.LdsViewActivity;
import com.elitetyc.customview.activity.ListCheckActivity;
import com.elitetyc.customview.activity.ProgressViewActivity;
import com.elitetyc.customview.activity.QrcodeActivity;
import com.elitetyc.customview.activity.ScrollerActivity;
import com.elitetyc.customview.activity.ZmxyActivity;
import com.elitetyc.customview.adapter.BottomDialogAdapter;
import com.elitetyc.customview.custom.TimeRulerView;
import com.elitetyc.customview.service.VideoLiveWallpaper;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import io.dcloud.PandoraEntry;
import io.dcloud.WebAppActivity;
import io.dcloud.multiprocess.activity.WebAppActivity1;
import io.dcloud.multiprocess.activity.WebAppActivity2;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_zmxy,btn_hlqh,btn_desktop_bg,btn_aqjp,btn_ch,btn_bottom_dialog,btn_download_progress,
            btn_activity_anim,btn_image_move,btn_lds,btn_list_check,btn_dialog,btn_qrcode,btn_webview,date_picker;
    private BottomDialogAdapter bottomDialogAdapter;

    private TimeRulerView timeRuler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        btn_zmxy = findViewById(R.id.btn_zmxy);
        btn_hlqh = findViewById(R.id.btn_hlqh);
        btn_desktop_bg = findViewById(R.id.btn_desktop_bg);
        btn_aqjp = findViewById(R.id.btn_aqjp);
        btn_aqjp.setOnClickListener(this);
        btn_desktop_bg.setOnClickListener(this);
        btn_zmxy.setOnClickListener(this);
        btn_hlqh.setOnClickListener(this);
        btn_ch = findViewById(R.id.btn_ch);
        btn_ch.setOnClickListener(this);
        btn_bottom_dialog = findViewById(R.id.btn_bottom_dialog);
        btn_bottom_dialog.setOnClickListener(this);
        btn_download_progress = findViewById(R.id.btn_download_progress);
        btn_download_progress.setOnClickListener(this);
        ImageView  iv_test = findViewById(R.id.iv_test);
        iv_test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "背景黑色圆晕", Toast.LENGTH_SHORT).show();
            }
        });
        ImageView  iv_test1 = findViewById(R.id.iv_test1);
        iv_test1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "背景白色圆晕", Toast.LENGTH_SHORT).show();
            }
        });
        btn_activity_anim = findViewById(R.id.btn_activity_anim);
        btn_activity_anim.setOnClickListener(this);
        btn_image_move = findViewById(R.id.btn_image_move);
        btn_image_move.setOnClickListener(this);
        btn_lds = findViewById(R.id.btn_lds);
        btn_lds.setOnClickListener(this);
        btn_list_check = findViewById(R.id.btn_list_check);
        btn_list_check.setOnClickListener(this);
        btn_dialog = findViewById(R.id.btn_dialog);
        btn_dialog.setOnClickListener(this);
        btn_qrcode = findViewById(R.id.btn_qrcode);
        btn_qrcode.setOnClickListener(this);
        btn_webview = findViewById(R.id.btn_webview);
        btn_webview.setOnClickListener(this);
        date_picker = findViewById(R.id.date_picker);
        date_picker.setOnClickListener(this);
        timeRuler = findViewById(R.id.timeRuler);
        timeRuler.setOnTimeChangeListener(new TimeRulerView.onTimeChangeListener() {
            @Override
            public void onTimeChangeed(double startTime, double endTime, boolean hasError) {
                Log.e("tyc","startTime:"+startTime+" endTime:"+endTime+" hasError:"+hasError);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_zmxy:
                startActivity(new Intent(MainActivity.this, ZmxyActivity.class));
                break;
            case R.id.btn_hlqh:
                startActivity(new Intent(MainActivity.this, HlqhActivity.class));
                break;
            case R.id.btn_desktop_bg:
                Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
                intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                        new ComponentName(this, VideoLiveWallpaper.class));
                startActivity(intent);
                break;
            case R.id.btn_aqjp:
                startActivity(new Intent(MainActivity.this, AnQuanJianPanActivity.class));
                break;
            case R.id.btn_ch:
                startActivity(new Intent(MainActivity.this, ScrollerActivity.class));
                break;
            case R.id.btn_bottom_dialog:

                RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_bottom_view,null);
                recyclerView.setLayoutManager(new LinearLayoutManager(this));
                final List<String> stringList = new ArrayList<>();
                for (int i=0;i<100;i++){
                    stringList.add("itemddd"+i);
                }
                final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
                bottomSheetDialog.setContentView(recyclerView);
                bottomDialogAdapter = new BottomDialogAdapter(this,stringList);
                bottomDialogAdapter.setOnItemClick(new BottomDialogAdapter.onItemClick() {
                    @Override
                    public void onItemClickLister(int pos) {
                        Toast.makeText(MainActivity.this, "点击了："+stringList.get(pos), Toast.LENGTH_SHORT).show();
                        bottomSheetDialog.dismiss();
                    }
                });
                recyclerView.setAdapter(bottomDialogAdapter);
                bottomSheetDialog.show();

                break;
            case R.id.btn_download_progress:
                startActivity(new Intent(MainActivity.this, ProgressViewActivity.class));
                break;
            case R.id.btn_activity_anim:
                startActivity(new Intent(MainActivity.this, ProgressViewActivity.class));
                overridePendingTransition(R.anim.anim_activity_in,R.anim.anim_activity_out);
                break;
            case R.id.btn_image_move:
//                View mImageView = findViewById(R.id.image);
//                View mTextView = findViewById(R.id.text);
//                Pair<View, String> imagePair = Pair.create(mImageView, getString(R.string.img));
//                Pair<View, String> textPair = Pair.create(mTextView, getString(R.string.name));
//                ActivityOptionsCompat compat = ActivityOptionsCompat
//                        .makeSceneTransitionAnimation(this,imagePair,textPair);
//                ActivityCompat.startActivity(this,new Intent(MainActivity.this, ImageMoveActivity.class),compat.toBundle());


                View mImageView = findViewById(R.id.iv_image);
                ActivityOptionsCompat compat = ActivityOptionsCompat
                        .makeSceneTransitionAnimation(this,mImageView,getResources().getString(R.string.img));
                ActivityCompat.startActivity(this,new Intent(MainActivity.this, ImageMoveActivity.class),compat.toBundle());

                break;
            case R.id.btn_lds:
                startActivity(new Intent(MainActivity.this, LdsViewActivity.class));
                break;
            case R.id.btn_list_check:
                startActivity(new Intent(MainActivity.this, ListCheckActivity.class));
                break;
            case R.id.btn_dialog:
                startActivity(new Intent(MainActivity.this, DialogActivity.class));
                break;
            case R.id.btn_qrcode:
                startActivity(new Intent(MainActivity.this, QrcodeActivity.class));
                break;
            case R.id.date_picker:

                startActivity(new Intent(MainActivity.this, DatePickerActivity.class));
                break;
            case R.id.btn_webview:
//                startActivity(new Intent(MainActivity.this, WebViewTestActivity.class));
                startActivity(new Intent(MainActivity.this, DanWebActivity.class));
                break;
            default:
                break;
        }
    }
}
